<?php

require("../head.php") ;

// Extraction du champ
$q = strtolower($_GET["q"]) ;
$q = preg_replace("/\s+/", " ", $q);
if (!$q) return ;
$noms = explode(' ', $q) ;
$dim = count($noms) ;

connect() ;
$requete = "SELECT * FROM Eleve" ;

if (!empty($q))
{
//   $requete .= " AND (" ;
   $premier = true ;
   foreach ($noms as $value)
   {
      if (empty($value)) continue ;
      if ($premier)
      {
         $requete .= " WHERE" ;
         $premier = false ;
      }
      else
         $requete .= " OR" ;
      $requete .= " nom LIKE \"{$value}%\" OR prenom LIKE \"{$value}%\" OR login LIKE \"{$value}%\"" ;
      //echo $value."<br/>".PHP_EOL ;
   }
   if (!$premier) $requete .= " OR";
}
$requete .= " 1=0;" ;

$result = executerRequete($requete, $GLOBALS['debug']) ;
while ($row = mysql_fetch_assoc($result))
{
   echo $row['id']."|".$row['prenom']."|".$row['nom']."|".$row['login']."\n" ;
}

mysql_close() ;
?>
